import 'package:flutter/material.dart';
import 'dart:async';

class LoadingPage extends StatefulWidget {
  const LoadingPage({super.key});

  @override
  State<StatefulWidget> createState() {
    return LoadingPageState();
  }
}

class LoadingPageState extends State<LoadingPage> {
  bool _visible = false;

  @override
  void initState() {
    super.initState();

    Future.delayed(const Duration(milliseconds: 200), (){
      setState(() {
        _visible = true;
      });
    });

    //在加载页面停顿3秒
    Future.delayed(const Duration(seconds: 3), (){
      print('Flutter 即时通讯 APP 界面实现 ....');
      Navigator.of(context).pushReplacementNamed('app');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: AnimatedOpacity(
        opacity: _visible ? 1.0 : 0.0,
        duration: const Duration(
          milliseconds: 1000
        ),
        child: Image.asset(
          'images/loading.jpeg',
          fit: BoxFit.cover,
        )
      ),
    );
  }

}